<?php
/**
 * @author Amissah Gideon<kuulmek@yahoo.com>
 * @access public
 * @version 1.0
 */

class SmsController extends AppController
{
    # Controller Name to be used
    var $name = 'Sms';

    # Models to be used
    var $uses = array(
        'Country','Contact','ContactGroup','SmsMeta','SmsOutbox','Config','User'
    );

    # set the layout to use
    var $layout = 'sms_layout';


    public function beforeFilter($param_array = null)
    {
        parent::beforeFilter();
    }

    # Controller actions
    /**
     * This function displays all the users in the system
     * @name index
     * @param void
     * @return Array of data.
     * @access public
     */
    function index(){
        $loggedUser = $this->Auth->user();
        $user_id = $loggedUser['id'];

        $page_title = 'Sms Managements';

        $local_sms_per_unit_cost = $this->Config->getValueByKey('local_sms_per_unit_cost');
        if(empty($local_sms_per_unit_cost)){
            $local_sms_per_unit_cost = 0;
        }
        $inter_sms_per_unit_cost = $this->Config->getValueByKey('international_sms_per_unit_cost');
        if(empty($inter_sms_per_unit_cost)){
            $inter_sms_per_unit_cost = 0;
        }
        $sms_per_unit_count = $this->Config->getValueByKey('sms_per_unit_count');
        if(empty($sms_per_unit_count)){
            $sms_per_unit_count = 160;
        }

        $time_opt = $this->geTimes();
        $days_opt = $this->getDays();
        $month_opt = $this->getMonths();
        $year_opt = $this->getYears(date('Y'),date('Y'));

        $contacts_in_group = $this->ContactGroup->countContactsInGroup($user_id);

        $notice_ifo = "Note that for every ".$sms_per_unit_count." characters we charge ".$local_sms_per_unit_cost." sms credit for local <br /> and ".$inter_sms_per_unit_cost." sms credit for international.";

        $page_title = 'Bulk SMS';
        $page_summary = 'Send SMS to your contacts';
        $page_icon = 'iconfa-envelope-alt';
        $this->set(compact('page_title','page_summary','page_icon','permissions','time_opt','days_opt','month_opt','year_opt','user_id','contacts_in_group','local_sms_per_unit_cost','inter_sms_per_unit_cost','sms_per_unit_count','notice_ifo'));
    }


    function single_sms(){
        $loggedUser = $this->Auth->user();
        $user_id = $loggedUser['id'];
        if ($this->request->is('ajax')) {
            # disable the rendering of the layout
            $this->autoRender = false;
            $this->autoLayout = false;

            $data = json_decode($_POST['data'], true);
            $post = $this->sanitize($data);
            $txt = $post['sms'];
            $sender_id = $post['sender_id'];
            $schedule = $post['schedule'];
            $schedule_date = isset($post['schedule_date'])?$post['schedule_date'] : date('Y-m-d H:i:s');
            $total_contacts = 0;
            $sms_cost = 0;
            $contacts = trim($post['sms_contacts']);
            $contact_arr = explode(',',$contacts);
            //$cost_per_contact = $sms_cost / $total_contacts;
            $sms_outbox = array();
            foreach($contact_arr as $contact){
                $fon_number = trim($contact);
                $country_code = substr($fon_number, 0, 3);
                $local_count = 0;
                $inter_count = 1;
                if($country_code == '233'){
                    $local_count = 1;
                    $inter_count = 0;
                }
                $cost_per_contact = $this->get_sms_cost($txt,$local_count,$inter_count);
                $sms_outbox[]=array(
                    'user_id'=>$user_id,
                    'phone_number'=>$fon_number,
                    'sender_id'=>$sender_id,
                    'message'=>$txt,
                    'cost'=>$cost_per_contact,
                    'status'=>'Pending',
                    'schedule'=>$schedule,
                    'schedule_date'=>$schedule_date,
                    'send_type'=>'System'
                );
                $total_contacts++;
                $sms_cost = $sms_cost + $cost_per_contact;
            }

            if(empty($sms_outbox)){
                return json_encode(array('code' => 1, 'msg' => 'No contacts Passed!'));
            }
            else{
                $sms = array(
                    'user_id'=>$user_id,
                    'message'=>$txt,
                    'cost'=>$sms_cost,
                    'sms_type'=>'Single',
                    'schedule'=>$schedule,
                    'schedule_date'=>$schedule_date,
                    'total_contacts'=>$total_contacts
                );

                $save_dava = array(
                    'SmsMeta'=>$sms,
                    'SmsOutbox'=>$sms_outbox
                );
            }

            $credit_balance = $this->User->getCreditBal($user_id);
            if($sms_cost > $credit_balance){
                $res_txt= "You don't have sufficient credit to send SMS!. SMS cost : ".$sms_cost." credit.";
                return json_encode(array('code' => 1, 'msg' => $res_txt));
            }

            # save the data
            if ($this->SmsMeta->saveAll($save_dava)) {
                //Deduct from User Credit Balance
                $this->User->debitCredit($user_id,$sms_cost);
                $new_credit_balance = $this->User->getCreditBal($user_id);
                $res_txt= 'Message Sent!';
                if($schedule == 'Later'){
                    $res_txt= 'Messages Scheduled To Be Sent At '.$schedule_date;
                }
                return json_encode(array('code' => 0, 'msg' => $res_txt, 'new_credit_bal'=>$new_credit_balance));
            } else {
                $res_txt= 'Sorry,your message could not be sent.';
                if($schedule == 'Later'){
                    $res_txt= 'Sorry,your messages could not be scheduled.';
                }
                return json_encode(array('code' => 1, 'msg' => $res_txt));
            }

        }

        $page_title = 'Sms Managements';

        $local_sms_per_unit_cost = $this->Config->getValueByKey('local_sms_per_unit_cost');
        if(empty($local_sms_per_unit_cost)){
            $local_sms_per_unit_cost = 0;
        }
        $inter_sms_per_unit_cost = $this->Config->getValueByKey('international_sms_per_unit_cost');
        if(empty($inter_sms_per_unit_cost)){
            $inter_sms_per_unit_cost = 0;
        }
        $sms_per_unit_count = $this->Config->getValueByKey('sms_per_unit_count');
        if(empty($sms_per_unit_count)){
            $sms_per_unit_count = 160;
        }

        $notice_ifo = "Note that for every ".$sms_per_unit_count." characters we charge ".$local_sms_per_unit_cost." sms credit for local <br /> and ".$inter_sms_per_unit_cost." sms credit for international.";

        $time_opt = $this->geTimes();
        $days_opt = $this->getDays();
        $month_opt = $this->getMonths();
        $year_opt = $this->getYears(date('Y'),date('Y'));

        $page_title = 'Single SMS';
        $page_summary = 'Send SMS to your contacts';
        $page_icon = 'iconfa-envelope-alt';
        $this->set(compact('page_title','page_summary','page_icon','permissions','time_opt','days_opt','month_opt','year_opt','user_id','local_sms_per_unit_cost','inter_sms_per_unit_cost','sms_per_unit_count','notice_ifo'));
    }

    /**
     * This function add a new record to the database
     * @name add
     * @param void
     * @return Json data
     * @access public
     */
    function sendSms_skip()
    {
        # Get the user session data
        $loggedUser = $this->Auth->user();
        # check whether the HTTP Request is an ajax request
        if ($this->request->is('ajax')) {
            # disable the rendering of the layout
            $this->autoRender = false;
            $this->autoLayout = false;
            $loggedUser_id = $loggedUser['id'];

            $data = json_decode($_POST['data'], true);
            $post = $this->sanitize($data);
            $txt = $post['sms'];
            $sender_id = $post['sender_id'];
            $schedule = $post['schedule'];
            $schedule_date = isset($post['schedule_date'])?$post['schedule_date'] : date('Y-m-d H:i:s');
            $sms_cost = 0;
            $total_contacts = 0;
            //$total_contacts = $post['total_contacts'];
            //$cost_per_contact = $sms_cost / $total_contacts;
            $sms_outbox = array();
            foreach($post['groups'] as $dt){
                $contact_group_id = $dt['contact_group_id'];
                //Get the
                $contact_group_data = $this->Contact->getContactGroupForSMS($loggedUser_id,$contact_group_id);
                foreach($contact_group_data as $contact){
                    $contact_id = $contact['Contact']['id'];
                    $phone = $contact['Contact']['country_code'].$contact['Contact']['phone_number'];
                    $country_code = $contact['Contact']['country_code'];
                    $local_count = 0;
                    $inter_count = 1;
                    if($country_code == '233'){
                        $local_count = 1;
                        $inter_count = 0;
                    }
                    $cost_per_contact = $this->get_sms_cost($txt,$local_count,$inter_count);
                    $sms_outbox[]=array(
                        'user_id'=>$loggedUser_id,
                        'contact_id'=>$contact_id,
                        'phone_number'=>$phone,
                        'sender_id'=>$sender_id,
                        'message'=>$txt,
                        'cost'=>$cost_per_contact,
                        'status'=>'Pending',
                        'schedule'=>$schedule,
                        'schedule_date'=>$schedule_date,
                        'send_type'=>'System'
                    );
                    $total_contacts++;
                    $sms_cost = $sms_cost + $cost_per_contact;
                }
            }

            if(empty($sms_outbox)){
                return json_encode(array('code' => 1, 'msg' => 'No contacts found!'));
            }
            else{
                $sms = array(
                    'user_id'=>$loggedUser_id,
                    'message'=>$txt,
                    'cost'=>$sms_cost,
                    'sms_type'=>'Bulk',
                    'schedule'=>$schedule,
                    'schedule_date'=>$schedule_date,
                    'total_contacts'=>$total_contacts
                );

                $save_dava = array(
                    'SmsMeta'=>$sms,
                    'SmsOutbox'=>$sms_outbox
                );
            }

            $credit_balance = $this->User->getCreditBal($loggedUser_id);
            if($sms_cost > $credit_balance){
                $res_txt= "You don't have sufficient credit to send SMS!. SMS cost : ".$sms_cost." credit.";
                return json_encode(array('code' => 1, 'msg' => $res_txt));
            }

            # save the data
            if ($this->SmsMeta->saveAll($save_dava)) {
                //Deduct from User Credit Balance
                $this->User->debitCredit($loggedUser_id,$sms_cost);
                $new_credit_balance = $this->User->getCreditBal($loggedUser_id);
                $res_txt= 'Message Sent!';
                if($schedule == 'Later'){
                    $res_txt= 'Messages Scheduled To Be Sent At '.$schedule_date;
                }
                return json_encode(array('code' => 0, 'msg' => $res_txt, 'new_credit_bal'=>$new_credit_balance));
            } else {
                $res_txt= 'Sorry,your message could not be sent.';
                if($schedule == 'Later'){
                    $res_txt= 'Sorry,your messages could not be scheduled.';
                }
                return json_encode(array('code' => 1, 'msg' => $res_txt));
            }
        }
    }



    function sms_uploads(){
        $this->autoRender = false;

        $upload_data = $this->Upload->__attach_files();

        $sender_id = isset($_POST['sender_id']) ? $_POST['sender_id']: '';

        //Get the file name
        $file_name = '';
        $save_to = '';
        foreach($upload_data['files'] as $key => $file){
            if(isset($file['name']) && !empty($file['name'])){
                $file_name = $file['name'];
                $save_to = $file['save_to'];
                break;
            }
        }
        $full_path = $save_to.'/';

        if($file_name){
            $res = $this->import_sms_file_and_send($file_name,$full_path,$sender_id);
            if(!$res['status']){
                $mesg = $res['mesg'];
                foreach($upload_data['files'] as $key => $file){
                    $upload_data['files'][$key]['error']= $mesg;
                }
            }
            else{
                $mesg = $res['mesg'];
                $credit_bal = $res['new_credit_bal'];
                $sms_outbox = $res['data'];
                foreach($upload_data['files'] as $key => $file){
                    $upload_data['files'][$key]['success']= $mesg;
                    $upload_data['files'][$key]['credit_bal']= $credit_bal;
                    //$upload_data['files'][$key]['data']= $sms_outbox;
                }
            }
        }
        else{
            foreach($upload_data['files'] as $key => $file){
                $upload_data['files'][$key]['error']= 'File was not uploaded.';
            }
        }

        $this->Upload->attachment_fire_response($upload_data);
    }


    function import_sms_file_and_send($filename,$full_path,$sender_id){
        # create folders if it does not exist
        $loggedUser = $this->Auth->user();
        $loggedUser_id = $loggedUser['id'];

        $folder = "files".DIRECTORY_SEPARATOR."user_".$loggedUser['id'].DIRECTORY_SEPARATOR;
        # setup directory pathname
        $folderAbsPath = WWW_ROOT . $folder;
        $folderRelPath = $folder;
        //chmod($folderAbsPath, 0777);
        try {
            $objPHPExcel = PHPExcel_IOFactory::load($folderAbsPath.$filename);
            /* $inputFileType = PHPExcel_IOFactory::identify($folderAbsPath.$filename);
             $objReader = PHPExcel_IOFactory::createReader($inputFileType);
             $objPHPExcel = $objReader->load($folderAbsPath.$filename);*/
        } catch(Exception $e) {
            return array('status'=>false,'mesg'=>$e->getMessage());
        }

        $schedule_date = date('Y-m-d H:i:s');
        $total_contacts = 0;
        $sms_cost = 0;
        $save = array();
        $sms_outbox = array();
        foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
            $worksheetTitle     = $worksheet->getTitle();
            $highestRow         = $worksheet->getHighestRow(); // e.g. 10
            $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
            $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
            $nrColumns = ord($highestColumn) - 64;

            for ($row =2; $row < ($highestRow + 1); ++$row){
                $fon_number = $objPHPExcel->getActiveSheet()->getCell("A".$row)->getValue();
                $txt_msg = $objPHPExcel->getActiveSheet()->getCell("B".$row)->getValue();
                $txt_msg = (string)$txt_msg;
                $country_code = substr($fon_number, 0, 3);
                $local_count = 0;
                $inter_count = 1;
                if($country_code == '233'){
                    $local_count = 1;
                    $inter_count = 0;
                }
                $cost_per_contact = $this->get_sms_cost($txt_msg,$local_count,$inter_count);

                if(!empty($fon_number)){
                    $sms_outbox[]=array(
                        'user_id'=>$loggedUser_id,
                        'phone_number'=>$fon_number,
                        'sender_id'=>$sender_id,
                        'message'=>$txt_msg,
                        'cost'=>$cost_per_contact,
                        'status'=>'Pending',
                        'schedule'=>'Now',
                        'schedule_date'=>$schedule_date,
                        'send_type'=>'Excel Import'
                    );
                    $total_contacts++;
                    $sms_cost = $sms_cost + $cost_per_contact;
                }
            }
        }

        if(empty($sms_outbox)){
            return array('status'=>false,'mesg'=>'No contacts found!');
        }
        else{
            $sms = array(
                'user_id'=>$loggedUser_id,
                'message'=>"Individual Message From Excel Import",
                'cost'=>$sms_cost,
                'sms_type'=>'Bulk',
                'total_contacts'=>$total_contacts
            );

            $save_dava = array(
                'SmsMeta'=>$sms,
                'SmsOutbox'=>$sms_outbox
            );
        }

        $credit_balance = $this->User->getCreditBal($loggedUser_id);
        if($sms_cost > $credit_balance){
            return array('status'=>false,'mesg'=>"You don't have sufficient credit to send SMS!. SMS cost : ".$sms_cost." credit.");
        }
        # save the data
        if ($this->SmsMeta->saveAll($save_dava)) {
            //Deduct from User Credit Balance
            $this->User->debitCredit($loggedUser_id,$sms_cost);
            $new_credit_balance = $this->User->getCreditBal($loggedUser_id);
            return array('status'=>true,'mesg'=>"Message Sent!", 'new_credit_bal'=>$new_credit_balance,'data'=>$sms_outbox);
        } else {
            return array('status'=>false,'mesg'=>'Sorry, but your message could not be sent.');
        }
    }



    function history($type = 'get'){
        $authUser = $this->Auth->user();
        $permissions = $this->action_permission;
        if ($this->request->is('ajax')) {
            $this->autoRender = false;
            $this->autoLayout = false;

            switch ($type) {
                case 'get' :
                    /**  Get posted data */
                    $page = isset($_POST['page']) ? $_POST['page'] : 1;
                    /** The current page */
                    $sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'id';
                    /** Sort column */
                    $sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';
                    /** Sort order */
                    $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : '';
                    /** Search column */
                    $search_query = isset($_POST['query']) ? $_POST['query'] : '';
                    /** Search string */
                    /** @var Filters  */
                    $filter_status =   isset($_POST['filter_status']) ? $_POST['filter_status'] : 'all' ;

                    $rp = isset($_POST['rp']) ? $_POST['rp'] : 10;
                    $limit = $rp;
                    $start = ($page - 1) * $rp;


                    $condition_array = array(
                        'SmsOutbox.user_id' => $authUser['id'],
                        //'SmsOutbox.send_type' => 'System',
                        'SmsOutbox.deleted' => 'n'
                    );
                    if($filter_status != 'all'){
                        $condition_array["SmsOutbox.status"] = $filter_status ;
                    }
                    $data_table = $this->SmsOutbox->find('all', array('conditions' => $condition_array, 'order' => "SmsOutbox.$sortname $sortorder", 'limit' => $start . ',' . $limit, 'recursive' => 1));
                    $data_table_count = $this->SmsOutbox->find('count', array('conditions' => $condition_array, 'recursive' => -1));

                    $total_records = $data_table_count;

                    if ($data_table) {
                        $return_arr = array();
                        foreach ($data_table as $obj) {
                            $return_arr[] = array(
                                'id' => $obj['SmsOutbox']['id'],
                                'cell' => array(
                                    $obj['SmsOutbox']['id'],
                                    $obj['SmsOutbox']['created'],
                                    $obj['SmsOutbox']['phone_number'],
                                    $obj['SmsOutbox']['message'],
                                    $obj['SmsOutbox']['status'],
                                    $obj['SmsOutbox']['cost']
                                )
                            );
                        }
                        return json_encode(array('success' => true, 'total' => $total_records, 'page' => $page, 'rows' => $return_arr));
                    }
                    else {
                        return json_encode(array('success' => false, 'total' => $total_records, 'page' => $page, 'rows' => array()));
                    }
                    break;
            }
        }

        $sms_status = array(
            array('id'=>'all','name'=>'All'),
            array('id'=>'Pending','name'=>'Pending'),
            array('id'=>'Delivered','name'=>'Delivered')
        );

        $page_title = 'SMS History';
        $page_summary = 'Manage SMS History';
        $page_icon = 'iconfa-inbox';
        $this->set(compact('page_title','page_summary','page_icon','permissions','sms_status'));

    }


    function export_history(){
        $loggedUser = $this->Auth->user();
        $user_id = $loggedUser['id'];
        # disable the rendering of the layout
        //$this->autoRender = false;
        $this->autoLayout = false;
        $download = false;
        $filter_status = isset( $_POST['export_filter_status']) ?  $_POST['export_filter_status'] : 'all';
        if ($_POST['export_type'] == 'selected') {
            $ids = explode(',', $_POST['export_ids']);
            $conditions = array("SmsOutbox.id" => $ids, 'SmsOutbox.user_id' => $user_id,"SmsOutbox.deleted" => 'n');
            if($filter_status != 'all'){
                $conditions["SmsOutbox.status"] = $filter_status ;
            }
            $export_data = $this->SmsOutbox->find('all', array(
                'conditions' => $conditions,
                'order' => array("SmsOutbox.id" => 'desc'),
                'recursive' => -1
            ));
        } else {
            $conditions = array('SmsOutbox.user_id' => $user_id,"SmsOutbox.deleted" => 'n');
            if($filter_status != 'all'){
                $conditions["SmsOutbox.status"] = $filter_status ;
            }
            $export_data = $this->SmsOutbox->find('all', array(
                'conditions' => $conditions,
                'order' => array("SmsOutbox.id" => 'desc'),
                'recursive' => -1
            ));
        }
        $message = '';
        if ($export_data) {
            $list_headers = array('Date','Phone Number','Message','SMS Status','Cost');
            $download = true;
            $list_data = array();
            foreach ($export_data as $value) {
                $list_data[] = array(
                    $value['SmsOutbox']['created'],
                    $value['SmsOutbox']['phone_number'],
                    $value['SmsOutbox']['message'],
                    $value['SmsOutbox']['status'],
                    $value['SmsOutbox']['cost'],
                );
            }

            $filename ="SMS History";
            $res = $this->convertToExcel($list_headers,$list_data,$filename);
            $objPHPExcel = $res['excel_obj'];
            $filename = $res['filename'];
        }
        else{
            $message = 'No SMS History To Export';
        }

        $this->set(compact('objPHPExcel', 'dowload', 'filename', 'download','message'));
    }



    function scheduled_sms($type = 'get'){
        $authUser = $this->Auth->user();
        $permissions = $this->action_permission;
        if ($this->request->is('ajax')) {
            $this->autoRender = false;
            $this->autoLayout = false;

            switch ($type) {
                case 'get' :
                    /**  Get posted data */
                    $page = isset($_POST['page']) ? $_POST['page'] : 1;
                    /** The current page */
                    $sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'id';
                    /** Sort column */
                    $sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';
                    /** Sort order */
                    $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : '';
                    /** Search column */
                    $search_query = isset($_POST['query']) ? $_POST['query'] : '';
                    /** Search string */
                    /** @var Filters  */
                    $filter_sms_type =   isset($_POST['filter_sms_type']) ? $_POST['filter_sms_type'] : 'all' ;

                    $rp = isset($_POST['rp']) ? $_POST['rp'] : 10;
                    $limit = $rp;
                    $start = ($page - 1) * $rp;


                    $cur_time=date("Y-m-d H:i:s");
                    $duration='+5 minutes';
                    $compare_date =  date('Y-m-d H:i:s', strtotime($duration, strtotime($cur_time)));

                    $condition_array = array(
                        'SmsMeta.user_id' => $authUser['id'],
                        'SmsMeta.schedule_date > ' => $compare_date,
                        'SmsMeta.schedule' => 'Later',
                        'SmsMeta.deleted' => 'n'
                    );
                    if($filter_sms_type != 'all'){
                        $condition_array["SmsMeta.sms_type"] = $filter_sms_type ;
                    }
                    $data_table = $this->SmsMeta->find('all', array('conditions' => $condition_array, 'order' => "SmsMeta.$sortname $sortorder", 'limit' => $start . ',' . $limit, 'recursive' => -1));
                    $data_table_count = $this->SmsMeta->find('count', array('conditions' => $condition_array, 'recursive' => -1));

                    $total_records = $data_table_count;

                    if ($data_table) {
                        $return_arr = array();
                        foreach ($data_table as $obj) {
                            $return_arr[] = array(
                                'id' => $obj['SmsMeta']['id'],
                                'cell' => array(
                                    $obj['SmsMeta']['id'],
                                    $obj['SmsMeta']['message'],
                                    $obj['SmsMeta']['total_contacts'],
                                    $obj['SmsMeta']['cost'],
                                    $obj['SmsMeta']['schedule_date'],
                                    $obj['SmsMeta']['sms_type']
                                )
                            );
                        }
                        return json_encode(array('success' => true, 'total' => $total_records, 'page' => $page, 'rows' => $return_arr));
                    }
                    else {
                        return json_encode(array('success' => false, 'total' => $total_records, 'page' => $page, 'rows' => array()));
                    }
                    break;

                case 'delete' :
                    if(!in_array('D',$permissions)){
                        return json_encode(array('code' => 1, 'msg' => 'Access Denied.'));
                    }
                    $response = $this->SmsMeta->deleteScheduledSMS($this->sanitize($_POST['ids']),$authUser['id']);
                    if($response){
                        return json_encode(array('code' => 0, 'msg' => 'Scheduled SMS deleted!.'));
                    }
                    else{
                        return json_encode(array('code' => 1, 'msg' => 'Cannot deleted Scheduled SMS.'));
                    }
                    break;
            }

        }

        $sms_type = array(
            array('id'=>'all','name'=>'All'),
            array('id'=>'Single','name'=>'Single'),
            array('id'=>'Bulk','name'=>'Bulk')
        );

        $page_title = 'Scheduled SMS';
        $page_summary = 'Scheduled SMS';
        $page_icon = 'iconfa-calendar';
        $this->set(compact('page_title','page_summary','page_icon','permissions','sms_type'));

    }


}